import { defineStore } from "pinia";
import { ref } from "vue";

/**
 * @description  导出用户的store
 */
export const useResidentStore = defineStore(
  "resident",
  () => {
    /**@data */
    const temporaryRid = ref("08ef9740-4022-11ef-9429-9f491e65c0b7"); // 临时存储的居民id
    /**@methods */
    /**@methods */
    const setTemporaryRid = (id: string) => {
      temporaryRid.value = id;
    };
    const clearTemporaryRid = () => {
      temporaryRid.value = "";
    };
    return {
      // 变量
      temporaryRid,
      // 方法
      setTemporaryRid,
      clearTemporaryRid,
    };
  },
  {
    // 配置持久化
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
        getItem(key) {
          return uni.getStorageSync(key);
        },
      },
    },
  }
);
